/**
 * 
 */
package com.csun.cmny.provider.vo;

import java.util.List;

/**
 * 分页查询
 * @author yangmin
 * 2017年9月18日
 */
public class Page<T> {
	
	private int pageNo;               //当前页码
	private int pageSize;             //分页大小
	private int totalCount;           //总记录数
	private int totalPageNum;         //总页数
	private List<T> list;             //分页数据
	
	
	public Page() {
		super();	
	}
	
	
	
	public Page(int pageNo, int pageSize, List<T> list) {
		//如果没有数据 直接返回
		if(list == null || list.size() == 0){
			return ;
		}
		
		//总数量
		this.totalCount = list.size();
		//分页大小
		this.pageSize = pageSize;
		
		//分页数
		this.totalPageNum = this.totalCount / this.pageSize;
		if(this.totalCount % this.pageSize !=0){
			this.totalPageNum += 1 ;
		}
		
		//当前页
		this.pageNo = this.totalPageNum < pageNo ? this.totalPageNum : pageNo;
		
	
		//起始索引
		int fromIndex = (this.pageNo-1) * this.pageSize;
		
		//结束索引
		int endIndex = this.pageNo * this.pageSize > this.totalCount 
				? this.totalCount : this.pageNo * this.pageSize;
		
		
		this.list = list.subList(fromIndex, endIndex);
		
	}



	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	public int getTotalPageNum() {
		return totalPageNum;
	}
	public void setTotalPageNum(int totalPageNum) {
		this.totalPageNum = totalPageNum;
	}
	public List<T> getList() {
		return list;
	}
	public void setList(List<T> list) {
		this.list = list;
	}
	
	
	
	
	

}
